
macro_rules! get {
    ($slice: expr, $idx: expr) => {
        unsafe { $slice.get_unchecked($idx) }
    };
    (^$slice: expr, $idx: expr) => {
        $slice.get_unchecked($idx)
    };
}

macro_rules! get_mut {
    ($slice: expr, $idx: expr) => {
        unsafe { $slice.get_unchecked_mut($idx) }
    };
    (^$slice: expr, $idx: expr) => {
        $slice.get_unchecked_mut($idx)
    };
}

macro_rules! chg {
    ($($obj: expr, $field: tt, $value: expr, $raw: expr), +) => {
        $(
            $raw = Rc::into_raw($obj) as *mut Node<T, V>;
            unsafe {
                (*$raw).$field = $value;
                $obj = Rc::from_raw($raw);
            }
        )+
    };
    ($(@$obj: expr, $field: tt, $value: expr, $raw: expr), +) => {
        $(
            $raw = Rc::into_raw($obj) as *mut Node<T, V>;
            unsafe {
                (*$raw).$field = $value;
                Rc::from_raw($raw);
            }
        )+
    };
    ($($obj: expr, $field: tt, $value: expr), +) => {
        let mut raw;
        $(
            raw = Rc::into_raw($obj) as *mut Node<T, V>;
            unsafe {
                (*raw).$field = $value;
                $obj = Rc::from_raw(raw);
            }
        )+
    };
    ($(@$obj: expr, $field: tt, $value: expr), +) => {
        let mut raw;
        $(
            raw = Rc::into_raw($obj) as *mut Node<T, V>;
            unsafe {
                (*raw).$field = $value;
                Rc::from_raw(raw);
            }
        )+
    };
    ($(^$obj: expr, $field: tt, $value: expr, $raw: expr), +) => {
        $(
            $raw = Rc::into_raw($obj) as *mut Node<T, V>;
            (*$raw).$field = $value;
            $obj = Rc::from_raw($raw);
        )+
    };
    ($(^@$obj: expr, $field: tt, $value: expr, $raw: expr), +) => {
        $(
            $raw = Rc::into_raw($obj) as *mut Node<T, V>;
            (*$raw).$field = $value;
            Rc::from_raw($raw);
        )+
    };
    ($(^$obj: expr, $field: tt, $value: expr), +) => {
        let mut raw;
        $(
            raw = Rc::into_raw($obj) as *mut Node<T, V>;
            (*raw).$field = $value;
            $obj = Rc::from_raw(raw);
        )+
    };
    ($(^@$obj: expr, $field: tt, $value: expr), +) => {
        let mut raw;
        $(
            raw = Rc::into_raw($obj) as *mut Node<T, V>;
            (*raw).$field = $value;
            Rc::from_raw(raw);
        )+
    };
}

//增节点
macro_rules! put {
    ($me: expr, $info: expr, $new: expr, $raw: expr) => {
        if let Some(upper) = Weak::upgrade(&$info.upper) {
            $raw = Rc::into_raw(upper) as *mut Node<T, V>;
            unsafe {
                (*$raw).children.insert($info.idx_in_children, $new);
                Rc::from_raw($raw);
            }
        } else {
            $me.root.insert($info.idx_in_children, $new);
        }
    };
}

//删节点
macro_rules! del {
    ($me: expr, $info: expr, $raw: expr) => {
        if let Some(upper) = Weak::upgrade(&$info.node.upper) {
            $raw = Rc::into_raw(upper) as *mut Node<T, V>;
            unsafe {
                (*$raw).children.remove($info.idx_in_children);
                Rc::from_raw($raw);
            }
        } else {
            $me.root.remove($info.idx_in_children);
        }
    };
}

macro_rules! put_default {
    ($me: expr, $info: expr, $key: expr, $value: expr, $raw: expr) => {
        let new = Rc::new(Node {
            kfield: $key.into_boxed_slice()[$info.idx_in_key..].to_owned().into_boxed_slice(),
            value: Some(Rc::new($value)),
            upper: Weak::clone(&$info.upper),
            children: Vec::with_capacity(0),
        });
        put!($me, $info, new, $raw);
    }
}

